import Mock from 'mockjs'

Mock.mock(/\/mock\/manage.*/, 'post', (options: any) => {
  const body = JSON.parse(options.body)
  console.log(body)
  let num = 41-(body.page-1)*5
  num = num >5?5:num

  const data = Mock.mock({
    [`list|${num}`]: [
        {
            'name|1': ['月餐(20日)','周餐(20日)'],
            'category|1': ['男士餐','女士餐','工作餐'],
            'price|1': [350,45,235,56,115,66],
            'times|1': [20,12,14,2,5,4,6],
            'status|1': ['是','否'],
          },
    
        ],
        total:41,
        pageSize:5,
    })
    if (body.input) {
        let categorylist =['男士餐', '女士餐', '工作餐']
        categorylist=  categorylist.filter(item=>{
          return item.includes(body.input)
        })
        if(categorylist[0]){
          // @ts-ignore
          data.list = data.list.map((item) => {
           const num = Math.floor(Math.random()*categorylist.length)
            item.category = categorylist[num]
            return item
          })
          data.total *= categorylist.length/3
         
        }
       
        else{
          data.list=[]
        }
    }
    return {
      data,
      code:200,
      message:'请求餐类列表成功',
    }
  })